package fun.chutianshu.entity;

public class Monster extends Character {

    public Monster(String name, int ap, int hp) {
        this.name = name;
        this.ap = ap;
        this.hp = hp;
    }

    public Monster() {
    }

    public Monster(String name, int ap, int hp, int x, int y) {
        super(name, ap, hp, x, y);
    }

    @Override
    public String toString() {
        return "怪物{" +
                "name='" + name + '\'' +
                ", ap=" + ap +
                ", hp=" + hp +
                ", 当前位置：x=" + this.getX() + ", y= "+ this.getY()+
                "}";
    }

    @Override
    public void attack(Character character){
        //先打怪
        //定义一个变量，存储怪物被打后的新血量
        int cHp = character.getHp() - this.ap;
        //将新血值赋值给怪物
        character.setHp(cHp);
        System.out.println(this.name+"大口一张，猛得咬了过来！"+character.getName()+"; "
                +character.getName()+"被打掉"+this.ap+"点血，还剩"+character.getHp()+"点血");
        //将怪物反击也写在当前打怪的方法中
        if(cHp>0)
        {
            this.hp -= character.getAp();
            System.out.println(character.getName()+"一剑砍来"+this.name+character.getAp()+"点血，"+this.name+"还剩"+this.hp+"点血。");
        }
        else {
            System.out.println(character.getName()+"血量少于零，已经挂了！");
        }
    }
}
